Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

447
Visualizações
How to solve "not a valid XPath expression" error in Cypress?

I used this string to find an element:

cy.xpath('//*[text()="search ${keyword}")]')

And when I run my test, it shows me the right result in console but also it shows me this error:

Failed to execute 'evaluate' on 'Document': The string '//*[text()="search ${keyword}")]' is not a valid XPath expression.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I used contains and it works. there is an icon in my XPath and it couldn't find just the text.

cy.xpath(`//*[contains(text(), 'search ${keyword}')]`)
about 4 years ago · Juan Pablo Isaza Relatório

0

Issue with your original question

The actual syntax error is due to an extraneous ):

cy.xpath('//*[text()="search ${keyword}")]')
                                        ^

Delete that character to eliminate the syntax error.

Issue with your self-answer

Your solution,

cy.xpath(`//*[contains(text(), 'search ${keyword}')]`)

doesn't do what you likely think it does. (It's only checking for substrings within the first text() node child of every element.) For full details, see this extensive explanation.

Instead, use

cy.xpath(`//*[text()[contains(., 'search ${keyword}')]]`)

or the other variation shown in the linked explanation per your requirements.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda